//!
//! # ty, type
//!

use serde::{Deserialize, Serialize};
use std::{convert::From, fmt, ops::Deref};

/// 后续优化为数字类型
#[derive(
    Debug,
    Clone,
    Hash,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Default,
    Serialize,
    Deserialize,
)]
pub struct ProjId(String);

impl ProjId {
    /// get inner str
    #[inline(always)]
    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }
}

impl From<ProjId> for String {
    #[inline(always)]
    fn from(id: ProjId) -> String {
        id.0
    }
}

impl From<String> for ProjId {
    #[inline(always)]
    fn from(s: String) -> ProjId {
        ProjId(s)
    }
}

impl From<&str> for ProjId {
    #[inline(always)]
    fn from(s: &str) -> ProjId {
        ProjId(s.to_owned())
    }
}

impl Deref for ProjId {
    type Target = str;

    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        self.0.as_str()
    }
}

impl fmt::Display for ProjId {
    #[inline(always)]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.0.as_str())
    }
}

/// 后续优化为数字类型
#[derive(
    Debug,
    Clone,
    Hash,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Default,
    Serialize,
    Deserialize,
)]
pub struct InstId(String);

impl InstId {
    /// get inner str
    #[inline(always)]
    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }
}

impl Deref for InstId {
    type Target = str;

    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        self.0.as_str()
    }
}

impl From<InstId> for String {
    #[inline(always)]
    fn from(id: InstId) -> String {
        id.0
    }
}

impl From<String> for InstId {
    #[inline(always)]
    fn from(s: String) -> InstId {
        InstId(s)
    }
}

impl From<&str> for InstId {
    #[inline(always)]
    fn from(s: &str) -> InstId {
        InstId(s.to_owned())
    }
}

impl fmt::Display for InstId {
    #[inline(always)]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.0.as_str())
    }
}
